package cn.livingCloud.controller.user.front;

import cn.livingCloud.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 微信自动登录
 * Created by 唐旭 on 2015/12/31.
 */
@Controller
@RequestMapping
public class AutoLoginController {

    @Autowired
    private MemberService service;

    /**
     * 自动获取用户信息
     * 如果有redirectUrl,则直接跳转到redirectUrl
     * 如果没有redirectUrl，则默认跳转到个人中心
     */
    @RequestMapping("/auto_login.htm")
    public String getUserInfo(@RequestParam String code, String redirectUrl, Model model) {
        service.loginByCode(code);
        if (!StringUtils.isEmpty(redirectUrl)) {
            return "redirect:" + redirectUrl;
        } else {
            return "redirect:/";
        }
    }

}
